﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
//CP
using DZ.Data_Modals;
namespace DZ.Data__Class
{
    class ClsAntibody
    {
        //DB_DZA_Context dbContext = new DB_DZA_Context();
        DB_DZA_Entities dbContext = new DB_DZA_Entities();
        public bool Save(TblAntibody NewAntibody)
        {
            dbContext.TblAntibodies.Add(NewAntibody);
            dbContext.SaveChanges();
            return true;
        }
        public bool SaveDetails(TblAntibodyDetail  NewAntibodyDetails)
        {
            dbContext.TblAntibodyDetails .Add(NewAntibodyDetails);
            dbContext.SaveChanges();
            return true;
        }
        public bool Update(TblAntibody NewAntibody)
        {

            using (var dbContext = new DB_DZA_Entities ())
            {
                //context.ClubMembers.Attach(clubMember);
                //context.Entry(clubMember).State = EntityState.Modified;
                //return context.SaveChanges() > 0;
                dbContext.TblAntibodies.Attach(NewAntibody);
                dbContext.Entry(NewAntibody).State = EntityState.Modified;
                return dbContext.SaveChanges() > 0;
            }

            //dbContext.TblAntibodies.Attach(NewAntibody);
            //dbContext.Entry(NewAntibody).State = EntityState.Modified;
            //dbContext.SaveChanges();
            //return true;
        }
        public bool UpdateDetails(TblAntibodyDetail  NewAntibodyDetails)
        {

            using (var dbContext = new DB_DZA_Entities())
            {
                //context.ClubMembers.Attach(clubMember);
                //context.Entry(clubMember).State = EntityState.Modified;
                //return context.SaveChanges() > 0;
                dbContext.TblAntibodyDetails .Attach(NewAntibodyDetails);
                dbContext.Entry(NewAntibodyDetails).State = EntityState.Modified;
                return dbContext.SaveChanges() > 0;
            }

            //dbContext.TblAntibodies.Attach(NewAntibody);
            //dbContext.Entry(NewAntibody).State = EntityState.Modified;
            //dbContext.SaveChanges();
            //return true;
        }
        //public bool Update(TblAntibody NewAntibody, string AntName)
        //{
        //    //Here TestEntities is the class which is given from "Save entity connection setting in web.config"

        //    //TestEntities context = new TestEntities();
        //    TblAntibody t = new TblAntibody();
        //    using (var ctx = new DB_DZA_Context ())
        //    {
        //        t = ctx.TblAntibodies.Where(s => s.AntiBodyName == AntName).FirstOrDefault<TblAntibody>();
        //    }
        //   //t.AnBID_PK  = dbContext.TblAntibodies.Where(S=>S.AntiBodyName==AntName).FirstOrDefault<TblAntibody>();

        //   var query = from data in dbContext.TblAntibodies 
        //                orderby data.AnBID_PK 
        //                select data;
        //    foreach (TblAntibody  details in query)
        //    {
        //        if (details.AnBID_PK  == t.AnBID_PK )
        //        {
        //            //Assign the new values to name whose id is 1
        //            details.H2O2IncubationTime  =0;
        //         }

        //    }

        //    //Save the changes back to database.

        //    dbContext.SaveChanges();


        //    return true;
        //}
        }
}
